import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.io.IOException;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        String paginationJsonStr = TxHelper.readTxt("files/paginationObject.txt");
        JSONObject paginationJsonObj = JSON.parseObject(paginationJsonStr);
        int pageSize = paginationJsonObj.getIntValue("pageSize");
        int pageNo = paginationJsonObj.getIntValue("pageNo");
        System.out.println("[分页参数]" + "pageNo:" + pageNo + "pageSize:" + pageSize );
        Pagination pagination = JSON.parseObject(paginationJsonStr, Pagination.class);
        System.out.println("[Java对象] pageSize" + pagination.getPageSize() + "pageNo" + pagination.getPageNo());
        String complexJsonStr = TxHelper.readTxt("files/complexObject.txt");
        JSONObject complexJsonObj = JSON.parseObject(complexJsonStr);
        String description = complexJsonObj.getString("description");
        System.out.println(description);
        JSONObject addressObj = complexJsonObj.getJSONObject("address");
        String city = addressObj.getString("city");
        String country = addressObj.getString("country");
        System.out.println("address:" + "[city:" + city + "country:" + country + "]");
        JSONArray conditionArray = complexJsonObj.getJSONArray("conditionList");
        List<Condition> conditions = JSON.parseArray(conditionArray.toJSONString(), Condition.class);
        System.out.println("[列表]" + "conditions:" + conditions);
        Pagination newPagination = new Pagination(10,3);
        String newPaginationJsonStr = JSON.toJSONString(newPagination);
        System.out.println("生成的JSON对象:" + newPaginationJsonStr);

    }
}
